package my.study.demo.outputinputstream;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
//https://blog.csdn.net/weixin_33583401/article/details/114554960
//利用程序将文件file1.txt 拷贝到file2.txt中。
public class FileOutAndInputStreamTest {public static void main(String args[]) throws IOException {
    try{

        // file的路径及文件本身必须要存在
        File inFile= new File("E:\\myjava\\file1.txt");
        File outFile= new File("E:\\myjava\\file2.txt");
        System.out.println(inFile.exists());
        System.out.println(outFile.exists());
        FileInputStream fileInStream = new FileInputStream(inFile);
        FileOutputStream fileOutStream = new FileOutputStream(outFile);
        byte[] buff = new byte[1024];//缓冲区
        int c;
        while ((c = fileInStream.read(buff)) != -1) {
            fileOutStream.write(buff);
        }

        fileInStream.close();
        fileOutStream.close();

        }catch(IOException e) {
        System.err.println("FileStreamsTest: " +e);
        }
    }
}
